﻿using System;
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using SqlSugar;
using System.Security.Claims;
using System.Collections.Generic;
using System.Linq;
using SqlSugar.Extensions;

namespace ComprehensiveSystem.Model.Entities
{
    /// <summary>
    /// 数据库实体的基类，所有的数据库实体属性类型都是可空值类型，为了在做条件查询的时候进行判断
    /// 虽然是可空值类型，null的属性值，在底层会根据属性类型赋值默认值，字符串是string.empty，数值是0，日期是1970-01-01
    /// </summary>
    public class BaseEntity
    {

        /// <summary>
        /// 自增ID
        /// </summary>
        [Display(Name = "自增ID")]
        [SugarColumn(IsPrimaryKey = true)]
        //[Required(ErrorMessage = "请输入{0}")]
        public string Id { get; set; }


        /// <summary>
        /// 删除标志（0 未删 1 已删）
        /// </summary>
        [Display(Name = "删除标志（0 未删 1 已删）")]
        public int? DeleteMark { get; set; } = 0;


        /// <summary>
        /// 创建时间
        /// </summary>
        [Display(Name = "创建时间")]
        public DateTime? CreateTime { get; set; }


        /// <summary>
        /// 更新时间
        /// </summary>
        [Display(Name = "更新时间")]
        public DateTime? LastModifyTime { get; set; }


        /// <summary>
        /// 删除时间
        /// </summary>
        [Display(Name = "删除时间")]
        public DateTime? DeleteTime { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [Display(Name = "")]
        public string CreateUserId { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [Display(Name = "")]
        public string LastModifyUserId { get; set; }


        /// <summary>
        /// 
        /// </summary>
        [Display(Name = "")]
        public string DeleteUserId { get; set; }

        //public virtual void Create()
        //{
        //    this.createTime = DateTime.Now;
        //    this.createUserId = Id;
        //    this.DeleteMark = 0;
        //}

        /// <summary>
        /// 新增调用
        /// </summary>
        public virtual void Create(int? id = 0)
        {
            CreateTime = DateTime.Now;
            //this.CreateUserId = id;
            DeleteMark = 0;
        }

        /// <summary>
        /// 编辑调用
        /// </summary>
        /// <param name="keyValue">主键值</param>
        public virtual void Modify(int? id = 0)
        {
            LastModifyTime = DateTime.Now;
            //OperatorInfo user = await Operator.Instance.Current();
            //if (user != null)
            //{
            //    this.LASTMODIFYUSERID = user.UserId;
            //}
            //else
            //{
            //this.LastModifyUserId = id;
            //}
        }
        /// <summary>
        /// 删除调用
        /// </summary>
        /// <param name="keyValue">主键值</param>
        public virtual void Remove(int? id = 0)
        {
            DeleteMark = 1;
            DeleteTime = DateTime.Now;
            //OperatorInfo user = await Operator.Instance.Current();
            //if (user != null)
            //{
            //    this.DELETEUSERID = user.UserId;
            //}
            //else
            //{
            //this.DeleteUserId = id;
            //}
        }
    }

    public class BaseMySqlEntity
    {

        /// <summary>
        /// 自增ID
        /// </summary>
        [Display(Name = "自增ID")]
        [SugarColumn(IsPrimaryKey = true)]
        //[Required(ErrorMessage = "请输入{0}")]
        public int id { get; set; }


        /// <summary>
        /// 删除标志（0 未删 1 已删）
        /// </summary>
        [Display(Name = "删除标志（0 未删 1 已删）")]
        public int? deleteMark { get; set; } = 0;


        /// <summary>
        /// 创建时间
        /// </summary>
        [Display(Name = "创建时间")]
        public DateTime? createTime { get; set; }


        /// <summary>
        /// 更新时间
        /// </summary>
        [Display(Name = "更新时间")]
        public DateTime? lastModifyTime { get; set; }


        /// <summary>
        /// 删除时间
        /// </summary>
        [Display(Name = "删除时间")]
        public DateTime? deleteTime { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [Display(Name = "")]
        public int? createUserId { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [Display(Name = "")]
        public int? lastModifyUserId { get; set; }


        /// <summary>
        /// 
        /// </summary>
        [Display(Name = "")]
        public int? deleteUserId { get; set; }

        //public virtual void Create()
        //{
        //    this.createTime = DateTime.Now;
        //    this.createUserId = Id;
        //    this.DeleteMark = 0;
        //}

        /// <summary>
        /// 新增调用
        /// </summary>
        public virtual void Create(int? id = 0)
        {
            createTime = DateTime.Now;
            //this.CreateUserId = id;
            deleteMark = 0;
        }

        /// <summary>
        /// 编辑调用
        /// </summary>
        /// <param name="keyValue">主键值</param>
        public virtual void Modify(int? id = 0)
        {
            lastModifyTime = DateTime.Now;
            //OperatorInfo user = await Operator.Instance.Current();
            //if (user != null)
            //{
            //    this.LASTMODIFYUSERID = user.UserId;
            //}
            //else
            //{
            //this.LastModifyUserId = id;
            //}
        }
        /// <summary>
        /// 删除调用
        /// </summary>
        /// <param name="keyValue">主键值</param>
        public virtual void Remove(int? id = 0)
        {
            deleteMark = 1;
            deleteTime = DateTime.Now;
            //OperatorInfo user = await Operator.Instance.Current();
            //if (user != null)
            //{
            //    this.DELETEUSERID = user.UserId;
            //}
            //else
            //{
            //this.DeleteUserId = id;
            //}
        }
    }
}
